package com.ticket.web.controller.yanchu;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ticket.common.constant.Constants;
import com.ticket.common.core.domain.model.LoginUser;
import com.ticket.framework.web.service.TokenService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ticket.common.annotation.Log;
import com.ticket.common.core.controller.BaseController;
import com.ticket.common.core.domain.AjaxResult;
import com.ticket.common.enums.BusinessType;
import com.ticket.system.domain.YanchuPlan;
import com.ticket.system.service.IYanchuPlanService;
import com.ticket.common.utils.poi.ExcelUtil;
import com.ticket.common.core.page.TableDataInfo;

/**
 * 演出计划Controller
 * 
 * @date 2023-04-06
 */
@RestController
@RequestMapping("/system/plan")
public class YanchuPlanController extends BaseController
{
    @Autowired
    private IYanchuPlanService yanchuPlanService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询演出计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(YanchuPlan yanchuPlan,HttpServletRequest request)
    {
        startPage();
        LoginUser user = tokenService.getLoginUser(request);
        yanchuPlan.setCreateUser(user.getUserId());
        if(null == yanchuPlan.getState()){
            yanchuPlan.setState(Constants.STATE_INIT);
        }
        List<YanchuPlan> list = yanchuPlanService.selectYanchuPlanList(yanchuPlan);
        return getDataTable(list);
    }

    /**
     * 查询演出计划列表
     */
    @GetMapping("/listDept")
    public TableDataInfo list(YanchuPlan yanchuPlan)
    {
        startPage();
        List<YanchuPlan> list = yanchuPlanService.selectYanchuPlanList(yanchuPlan);
        return getDataTable(list);
    }

    /**
     * 导出演出计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:export')")
    @Log(title = "演出计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YanchuPlan yanchuPlan)
    {
        List<YanchuPlan> list = yanchuPlanService.selectYanchuPlanList(yanchuPlan);
        ExcelUtil<YanchuPlan> util = new ExcelUtil<YanchuPlan>(YanchuPlan.class);
        util.exportExcel(response, list, "演出计划数据");
    }

    /**
     * 获取演出计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yanchuPlanService.selectYanchuPlanById(id));
    }

    /**
     * 新增演出计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:add')")
    @Log(title = "演出计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YanchuPlan yanchuPlan, HttpServletRequest request)
    {
        LoginUser user = tokenService.getLoginUser(request);
        yanchuPlan.setCreateUser(user.getUserId());
        yanchuPlan.setUpdateTime(new Date());
        yanchuPlan.setDeptId(user.getDeptId());
        yanchuPlan.setCreateTime(new Date());
        if(null==yanchuPlan.getState()){
            yanchuPlan.setState(Constants.STATE_INIT);
        }

        return toAjax(yanchuPlanService.insertYanchuPlan(yanchuPlan));
    }

    /**
     * 修改演出计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:edit')")
    @Log(title = "演出计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YanchuPlan yanchuPlan)
    {
        return toAjax(yanchuPlanService.updateYanchuPlan(yanchuPlan));
    }

    /**
     * 删除演出计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:remove')")
    @Log(title = "演出计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yanchuPlanService.deleteYanchuPlanByIds(ids));
    }

    /**
     * 查询集团汇总
     */
    @ApiOperation("查询集团汇总")
//    @PreAuthorize("@ss.hasRole('groupMgr')")
    @GetMapping("/listGroup")
    public TableDataInfo listGroup(YanchuPlan yanchuPlan)
    {
        startPage();
        List<YanchuPlan> list = yanchuPlanService.selectGroupList(yanchuPlan);
        return getDataTable(list);
    }
}
